package com.young.springdemo.utils.domain;


import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "myapi")
@ResponseBody
public class TestController {

    @RequestMapping(value = "test",method = RequestMethod.GET)
    public  void getTest(){
        System.out.println("无参GET方法，调用成功");
        return;
    }

    @RequestMapping(value = "getParam",method = RequestMethod.GET)
    @ResponseBody
    public String getParam(@RequestParam String name,@RequestParam String age) {
        System.out.println("有参GET,获取到的参数name位：" + name+"==== age:"+age);
        return name;
    }

    @RequestMapping(value = "getPost",method = RequestMethod.POST)
    @ResponseBody
    public String getPost(){
        System.out.println("调用无参post成功");
        return "SUCCESS";
    }

    @RequestMapping(value = "getPostParam",method = RequestMethod.POST)
    @ResponseBody
    public String getPostParam(@RequestParam("name")String name){
        System.out.println("调用有参成功，name："+name);
        DemoResp demoResp = new DemoResp();
        demoResp.setName(name);
        return name;
    }

    @RequestMapping(value = "getPostResult",method = RequestMethod.POST)
    @ResponseBody
    public ResponseData getPostResult(){
        System.out.println("调用无参post成功");
        return new ResponseData<DemoResp>().setCode("200");
    }

    @RequestMapping(value = "getPostParamResult",method = RequestMethod.POST)
    @ResponseBody
    public ResponseData<DemoResp> getPostParamResult(@RequestParam("name")String name){
        System.out.println("调用有参成功，name："+name);
        DemoResp demoResp = new DemoResp();
        demoResp.setName(name);
        return new ResponseData<DemoResp>().setCode("200").setData(demoResp);
    }


    @RequestMapping(value = "getPostParamEntityResult",method = RequestMethod.POST)
    @ResponseBody
    public ResponseData<DemoResp> getPostParamResult(@RequestBody DemoResp resParam){
        System.out.println("调用有参成功，name："+resParam.toString());
        return new ResponseData<DemoResp>().setCode("200").setData(resParam);
    }
}
